<template>
  <div>
    <!-- <el-upload
      action="#"
      list-type="picture-card"
      :on-preview="handlePictureCardPreview"
      :on-change="handleChange"
      :on-remove="handleRemove"
      :auto-upload="false"
      :file-list="fileList"
      multiple
      :limit="1"
    >
      <i class="el-icon-plus"></i>
    </el-upload> -->
    <el-upload
      class="avatar-uploader"
      action=""
      :auto-upload="false"
      :show-file-list="false"
      :on-change="handleChange"
    >
      <img v-if="imageUrl" :src="imageUrl" class="avatar" />
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>

    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "MvCloudgateTerminalUploadImg",
  props: {
    imgUrl: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      dialogImageUrl: "",
      dialogVisible: false,
      imageUrl: "",
    };
  },
  mounted() {},
  watch: {
    imgUrl: function (newMsg, oldMsg) {
      this.imageUrl = newMsg;
    },
  },
  methods: {
    handleChange(file, fileList) {
      this.$emit("handleUploadChange", file);
    },
    createImage(file) {
      this.imageUrl = URL.createObjectURL(file.raw);
    },
  },
};
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
